package com.lbd.media.controller;

import com.lbd.media.bean.WebLink;
import com.lbd.media.service.WebLinkService;
import com.lbd.base.controller.BaseController;
import com.lbd.commons.Result;
import com.lbd.commons.ResultState;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/weblink")
public class WebLinkController extends BaseController {
    private final Logger log = Logger.getLogger(this.getClass());

    @Autowired
    private WebLinkService weblinkService;

    /**
     * 按条件分页查询weblink
     *
     * @param page    第几页
     * @param rows    一页多少条
     * @param weblink
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result list(int page, int rows, WebLink weblink) {
        return new Result(ResultState.SUCCESS, "查询成功", weblinkService.findByPageConditionJpql(page, rows, weblink));
    }

    /**
     * 保存weblink信息
     *
     * @param weblink
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(WebLink weblink) {
        weblinkService.save(weblink);
        return new Result(ResultState.SUCCESS, "添加成功", "");
    }

    /**
     * 根据id查询回显要编辑的WebLink
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public Result toEdit(String id) {
        return new Result(ResultState.SUCCESS, "加载成功", weblinkService.findById(id));
    }

    /**
     * 修改weblink信息
     *
     * @param weblink
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public Result update(WebLink weblink) {
        weblinkService.update(weblink);
        return new Result(ResultState.SUCCESS, "更新成功");
    }

    /**
     * 删除Banner信息
     *
     * @param ids
     * @return
     */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    public Result del(@RequestParam("ids[]") String[] ids) {
        weblinkService.del(ids);
        return new Result(ResultState.SUCCESS, "删除成功", "");

    }

}
